package UIPackage;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JTextField;
import javax.swing.SwingUtilities;
import javax.swing.UIManager;

import org.dyno.visual.swing.layouts.Constraints;
import org.dyno.visual.swing.layouts.GroupLayout;
import org.dyno.visual.swing.layouts.Leading;

import Sistem.Register;

//VS4E -- DO NOT REMOVE THIS LINE!
public class AnasayfaSatisElemaniGUI extends JFrame {

	private static final long serialVersionUID = 1L;
	private JButton jButton1;
	private JButton jButton2;
	private JButton jButton0;
	private JTextField jTextField0;
	private JTextField jTextField1;
	private JTextField jTextField2;
	private Register r;
	private static final String PREFERRED_LOOK_AND_FEEL = "javax.swing.plaf.metal.MetalLookAndFeel";
	public AnasayfaSatisElemaniGUI() {
		initComponents();
	}
	public AnasayfaSatisElemaniGUI(Register r){
		this.r=r;
		initComponents();
	}
	private void initComponents() {
		setLayout(new GroupLayout());
		add(getJButton0(), new Constraints(new Leading(194, 198, 12, 12), new Leading(34, 12, 12)));
		add(getJTextField0(), new Constraints(new Leading(40, 101, 10, 10), new Leading(34, 25, 12, 12)));
		add(getJTextField1(), new Constraints(new Leading(39, 102, 12, 12), new Leading(81, 25, 12, 12)));
		add(getJTextField2(), new Constraints(new Leading(39, 102, 12, 12), new Leading(127, 25, 12, 12)));
		add(getJButton1(), new Constraints(new Leading(194, 198, 12, 12), new Leading(81, 12, 12)));
		add(getJButton2(), new Constraints(new Leading(193, 200, 12, 12), new Leading(127, 10, 10)));
		setSize(439, 269);
	}
	private JTextField getJTextField2() {
		if (jTextField2 == null) {
			jTextField2 = new JTextField();
		}
		return jTextField2;
	}
	private JTextField getJTextField1() {
		if (jTextField1 == null) {
			jTextField1 = new JTextField();
		}
		return jTextField1;
	}
	private JTextField getJTextField0() {
		if (jTextField0 == null) {
			jTextField0 = new JTextField();
		}
		return jTextField0;
	}
	private JButton getJButton0() {
		if (jButton0 == null) {
			jButton0 = new JButton();
			jButton0.setText("Müşteri Ekleme");
			jButton0.addMouseListener(new MouseAdapter() {
	
				public void mouseClicked(MouseEvent event) {
					jButton0MouseMouseClicked(event);
				}
			});
		}
		return jButton0;
	}
	private JButton getJButton2() {
		if (jButton2 == null) {
			jButton2 = new JButton();
			jButton2.setText("Kargo Bilet Satışı");
			jButton2.addMouseListener(new MouseAdapter() {
	
				public void mouseClicked(MouseEvent event) {
					jButton2MouseMouseClicked(event);
				}
			});
		}
		return jButton2;
	}
	private JButton getJButton1() {
		if (jButton1 == null) {
			jButton1 = new JButton();
			jButton1.setText("Yolcu Bilet Satışı");
			jButton1.addMouseListener(new MouseAdapter() {
	
				public void mouseClicked(MouseEvent event) {
					jButton1MouseMouseClicked(event);
				}
			});
		}
		return jButton1;
	}
	private static void installLnF() {
		try {
			String lnfClassname = PREFERRED_LOOK_AND_FEEL;
			if (lnfClassname == null)
				lnfClassname = UIManager.getCrossPlatformLookAndFeelClassName();
			UIManager.setLookAndFeel(lnfClassname);
		} catch (Exception e) {
			System.err.println("Cannot install " + PREFERRED_LOOK_AND_FEEL
					+ " on this platform:" + e.getMessage());
		}
	}

	/**
	 * Main entry of the class.
	 * Note: This class is only created so that you can easily preview the result at runtime.
	 * It is not expected to be managed by the designer.
	 * You can modify it as you like.
	 */
	public static void main(String[] args) {
		installLnF();
		SwingUtilities.invokeLater(new Runnable() {
			@Override
			public void run() {
				AnasayfaSatisElemaniGUI frame = new AnasayfaSatisElemaniGUI();
				frame.setDefaultCloseOperation(AnasayfaSatisElemaniGUI.EXIT_ON_CLOSE);
				frame.setTitle("AnasayfaSatisElemani");
				frame.getContentPane().setPreferredSize(frame.getSize());
				frame.pack();
				frame.setLocationRelativeTo(null);
				frame.setVisible(true);
			}
		});
	}

	private void jButton0MouseMouseClicked(MouseEvent event) {
		try {
			Integer.parseInt(jTextField0.getText());	
			int musteriID=Integer.parseInt(getJTextField0().getText());
			r.musteriEklemeIsleminiBaslat(musteriID);
			MusteriEkleGUI form = new MusteriEkleGUI(r);
			form.show();
			
		}catch (NumberFormatException e) {
			System.out.println("müşteri id hatalı!");
		}
		
		
	}

	private void jButton1MouseMouseClicked(MouseEvent event) {
		try {	
			if(r.yolcuBiletSatisIsleminiBaslat(Integer.parseInt(jTextField1.getText()))){
				YolcuBiletSatisTarihGUI form = new YolcuBiletSatisTarihGUI(r);
				form.show();
			}
			else{
				System.out.println("musteri kayitli degil");
			}
			
		}catch (NumberFormatException e) {
			System.out.println("musteri id hatalı!");
		}
		
	}

	private void jButton2MouseMouseClicked(MouseEvent event) {
		try {
			if (r.kargoBiletSatisIsleminiBaslat(Integer.parseInt(jTextField2.getText()))){
				KargoBiletSatisTarihGUI form = new KargoBiletSatisTarihGUI(r);
				form.show();
			}
			else{
				System.out.println("musteri kayitli degil");
			}			
		}catch (NumberFormatException e) {
			System.out.println("musteri id hatalı!");
		}
		
	}

}
